package com.aglhz.nature.adapter;

import java.util.List;


import com.aglhz.nature.R;
import com.aglhz.nature.modle.item.SearchData;

import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.TextView;




public class SearchAdapter extends BaseAdapter{
	public List<SearchData>mData;
    public Context context;
	public SearchAdapter(List<SearchData> mData, Context context) {
		super();
		this.mData = mData;
		this.context = context;
	}
	@Override
	public int getCount() {
		return mData.size();
	}
	@Override
	public Object getItem(int position) {
		return mData.get(position);
	}
	@Override
	public long getItemId(int position) {
		return position;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup arg2) {
		 ViewHolder viewHolder; 
			if(null==convertView){			
				  convertView = LayoutInflater.from(context).inflate(R.layout.item_search, null); 
				  viewHolder = new ViewHolder();
				  
				  viewHolder.item_search_textView= (TextView) convertView.findViewById(R.id.item_search_textView); 
				 
				  convertView.setTag(viewHolder); 
			}else{
				viewHolder = (ViewHolder) convertView.getTag(); 
			}
			
	   
			//设置文字
//			viewHolder.item_search_textView.setText(mData.get(position).getName());
			
			
			int screenWidth = getScreenWidth();
			GridView.LayoutParams p=new GridView.LayoutParams(screenWidth/3,screenWidth/3);
			convertView.setLayoutParams(p);

			return convertView;
		}
		class ViewHolder 
		{  
		    public TextView item_search_textView;

		} 
		
		/**
		 * 获取屏幕宽度
		 * 
		 * @return
		 */
		protected int getScreenWidth() {
			WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
			Display display = wm.getDefaultDisplay();
			return display.getWidth();
		}
    
    
}
